package com.SpringMVC.WebBindingInitializer;

import com.SpringMVC.Format.TestFormat;
import com.SpringMVC.PropertyEditor.UserPropertyEditor;
import com.SpringMVC.vo.User;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

/**
 * Created by 41579 on 2017/5/20.
 */
public class MyWebBindingInitializer implements WebBindingInitializer{
    @Override
    public void initBinder(WebDataBinder webDataBinder, WebRequest webRequest) {
        webDataBinder.registerCustomEditor(User.class, new UserPropertyEditor());
        //设置自定义格式化
        FormattingConversionService formattingConversionService = new FormattingConversionService();
        formattingConversionService.addFormatter(new TestFormat());
        webDataBinder.setConversionService(formattingConversionService);
    }
}
